package net.gxtvsgwt.client.demo.type;

import net.gxtvsgwt.client.demo.BaseDemo;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class MediumMixDemo extends BaseDemo {

	@Override
	public Widget createGxt() {

		HorizontalPanel panel = new HorizontalPanel();

		for (int i = 0; i < dataSize; i++) {

			com.extjs.gxt.ui.client.widget.Label title = new com.extjs.gxt.ui.client.widget.Label(
					"Title");
			com.extjs.gxt.ui.client.widget.VerticalPanel header = new com.extjs.gxt.ui.client.widget.VerticalPanel();
			header.add(title);

			com.extjs.gxt.ui.client.widget.form.TextField<String> field0 = new com.extjs.gxt.ui.client.widget.form.TextField<String>();
			field0.setValue("Value 0");
			field0.setFieldLabel("Label 0");
			com.extjs.gxt.ui.client.widget.form.SimpleComboBox<String> field1 = new com.extjs.gxt.ui.client.widget.form.SimpleComboBox<String>();
			field1.add("Value 1");
			field1.setFieldLabel("Label 1");
			field1.setForceSelection(true);
			field1.setLazyRender(false);
			com.extjs.gxt.ui.client.widget.form.CheckBox field2 = new com.extjs.gxt.ui.client.widget.form.CheckBox();
			field2.setFieldLabel("Label 2");
			com.extjs.gxt.ui.client.widget.form.Radio field3 = new com.extjs.gxt.ui.client.widget.form.Radio();
			field3.setFieldLabel("Label 3");

			com.extjs.gxt.ui.client.widget.form.FormPanel body = new com.extjs.gxt.ui.client.widget.form.FormPanel();
			body.setHeaderVisible(false);
			body.setBodyBorder(false);
			body.add(field0);
			body.add(field1);
			body.add(field2);
			body.add(field3);

			com.extjs.gxt.ui.client.widget.button.Button save = new com.extjs.gxt.ui.client.widget.button.Button(
					"Save");
			com.extjs.gxt.ui.client.widget.button.Button cancel = new com.extjs.gxt.ui.client.widget.button.Button(
					"Cancel");
			com.extjs.gxt.ui.client.widget.HorizontalPanel buttons = new com.extjs.gxt.ui.client.widget.HorizontalPanel();
			buttons.add(save);
			buttons.add(cancel);

			com.extjs.gxt.ui.client.widget.VerticalPanel form = new com.extjs.gxt.ui.client.widget.VerticalPanel();
			form.add(header);
			form.add(body);
			form.add(buttons);

			panel.add(form);
		}

		return panel;
	}

	@Override
	public Widget createGwt() {

		HorizontalPanel panel = new HorizontalPanel();

		for (int i = 0; i < dataSize; i++) {

			Label title = new Label("Title");
			VerticalPanel header = new VerticalPanel();
			header.add(title);

			Label label0 = new Label("Label 0");
			TextBox field0 = new TextBox();
			field0.setValue("Value 0");
			Label label1 = new Label("Label 1");
			ListBox field1 = new ListBox();
			field1.addItem("Value 1");
			Label label2 = new Label("Label 2");
			CheckBox field2 = new CheckBox();
			Label label3 = new Label("Label 3");
			RadioButton field3 = new RadioButton("field3");

			FlexTable body = new FlexTable();
			body.setWidget(0, 0, label0);
			body.setWidget(0, 1, field0);
			body.setWidget(1, 0, label1);
			body.setWidget(1, 1, field1);
			body.setWidget(2, 0, label2);
			body.setWidget(2, 1, field2);
			body.setWidget(3, 0, label3);
			body.setWidget(3, 1, field3);

			Button save = new Button("Save");
			Button cancel = new Button("Cancel");
			HorizontalPanel buttons = new HorizontalPanel();
			buttons.add(save);
			buttons.add(cancel);

			VerticalPanel form = new VerticalPanel();
			form.add(header);
			form.add(body);
			form.add(buttons);

			panel.add(form);
		}

		return panel;
	}

	@Override
	public String getName() {
		return "Medium Mix - Form";
	}
}
